home *** CD-ROM | disk | FTP | other *** search
- #define N 10
-
- /*****************************************************************************
- * power() *
- *****************************************************************************
- * DESCRIPTION: Raises a real number to an integer power. *
- * *
- * SYNOPSIS: double power(a, n); Raise a to the nth power *
- * double a; *
- * int n; *
- * *
- * REVISIONS: 20 DEC 88 - RAC - Original code *
- *****************************************************************************/
-
- double power(a, n)
- double a;
- int n;
- {
- double rv; /* Return value */
-
- rv = 1;
- while (n--) rv *= a;
- return rv;
- } /* End power() */
- /*****************************************************************************
- * polyfit() *
- *****************************************************************************
- * DESCRIPTION: Finds the mean square regression curve (or line) for a set *
- * of points, as shown on pp 172-3 of Burington's "Handbook *
- * of Mathematical Tables and Formulas". *
- * *
- * SYNOPSIS: polyfit(n, data, k, A); *
- * int n; Degree of polynomial desired *
- * int k; Number of data points *
- * double *data; Pointer to (2 by k) array of *
- * (x, y) points *
- * double *A; Pointer to result array *
- * *
- * REVISIONS: 19 DEC 88 - RAC - Original code *
- *****************************************************************************/
-
- polyfit(n, data, k, A)
- int n;
- int k;
- double data[][2];
- double A[N];
- {
- int i, j, row, col; /* Local temps */
- double S, T; /* See Burington, p. 173 */
- double ST[N][N+1];
-
- for (j=0; j<=(2*n); j++) { /* Calculate all the S's */
- if (j == 0) S = k; /* S0 is a special case */
- else { /* All others are normal */
- S = 0;
- for (i=0; i<k; i++)
- S += power(data[i][0], j);
- }
- for (row=0; row<=n; row++) /* Put S where it goes in */
- for (col=0; col<=n; col++) /* the big array */
- if (j == (row + col))
- ST[row][col] = S;
- } /* End 'calculate the S's */
- for (j=0; j<=n; j++) { /* Calculate all the T's and */
- T = 0; /* stick them in the big */
- for (i=0; i<k; i++) /* array */
- T += (power(data[i][0], j) * data[i][1]);
- ST[j][n+1] = T;
- } /* End 'calculate the T's */
- simul(ST, A, n+1); /* Go solve the equations */
- } /* End polyfit() */
-